#!/bin/bash

echo "======================================================================"
echo "🌐 法语学习系统 Web服务器启动"
echo "======================================================================"
echo ""

cd "$(dirname "$0")/web_app"

echo "📂 当前目录: $(pwd)"
echo ""

echo "🔧 激活Conda环境..."
eval "$(conda shell.bash hook)"
conda activate whisper-env

if [ $? -ne 0 ]; then
    echo "❌ 无法激活whisper-env环境"
    echo "   请确保已创建该环境"
    exit 1
fi

echo "✓ 环境已激活"
echo ""

echo "📦 检查依赖..."
python -c "import flask" 2>/dev/null
if [ $? -ne 0 ]; then
    echo "⚠️  Flask未安装，正在安装..."
    pip install -r requirements.txt
fi

echo "✓ 依赖检查完成"
echo ""

export HF_ENDPOINT=https://hf-mirror.com

echo "🚀 启动Flask服务器..."
echo ""
echo "======================================================================"
echo "📍 访问地址:"
echo "   本地: http://127.0.0.1:5001"
echo "   局域网: http://0.0.0.0:5001"
echo ""
echo "📄 页面:"
echo "   录音翻译: http://127.0.0.1:5001/"
echo "   单词本: http://127.0.0.1:5001/vocabulary"
echo ""
echo "⚠️  按 Ctrl+C 停止服务器"
echo "======================================================================"
echo ""

python app.py

